package jetbrains.buildServer.cuta.logic.operators;

import jetbrains.buildServer.cuta.logic.ColumnDef;
import jetbrains.buildServer.serverSide.BuildAgentManager;
import jetbrains.buildServer.serverSide.SBuildAgent;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.Map;



/**
 * @author Leonid Bushuev from JetBrains
 */
class GetAgentPolicyOperator extends GetAgentVarOperator
{

    private BuildAgentManager myBAM;


    @Override
    public void init(Element element, ColumnDef column, ExternalContext extContext)
    {
        super.init(element, column, extContext);
        myBAM = extContext.getBuildAgentManager();
    }


    @Override
    @NotNull
    protected Map<String,String> getVars(SBuildAgent agent)
    {
        boolean specific =
                myBAM.getRunConfigurationPolicy(agent) == BuildAgentManager.RunConfigurationPolicy.SELECTED_COMPATIBLE_CONFIGURATIONS;
        return Collections.singletonMap("runConfigurationPolicy", specific ? "S" : "A");
    }


    @Override
    @NotNull
    protected String getNamePrefix() { return ""; }


    @Override
    @NotNull
    public String name() { return "get-agent-policy"; }


}
